<template>
	<view class="register-view">
		<view class="logo">
			<image src="@/static/icon/image_60.png" mode="" class="register-image"></image>
		</view>

		<view class="input-all">
			<view class="hint">
				已对邮箱{{ email }}发送验证码
			</view>
			<input type="text" v-model="code" placeholder="请输入验证码" class="password" @focus="hideHint">
			<view class="vercode-err" v-if="isVerCode">
				<image src="@/static/icon/image_20.png" class="ver-img" alt=""></image>
				验证码错误，请重新输入
			</view>
			
			<view class="vercode-err" v-if="isPastCode">
				<image src="@/static/icon/image_20.png" class="ver-img" alt=""></image>
				验证码过期，请重新输入
			</view>
		</view>

		<view class="register-but" @tap="nextStep">
			登录
		</view>
	</view>
</template>
<script>
	import { checkEmailCode } from "@/common/api.js"
	
	export default {
		data() {
			return {
				email: "",
				code: "",
				isVerCode: false,
				isPastCode: false
			}
		},
		methods: {
			hideHint() {
				this.isVerCode = false;
				this.isPastCode = false;
			},
			async nextStep() {
				const { msg, code } = await checkEmailCode(this.email, this.code);
				if(msg==="验证码错误") {
					this.isVerCode = true;
					return
				} else if (msg==="验证码过期") {
					this.isPastCode = true;
					return
				}
				
				if(code === 200) {
					uni.switchTab({
						url: "/pages/home/home"
					})
				}
			}
		},
		onLoad(options) {
			this.email = options.email;
		}
	}
</script>

<style lang="scss" scoped>
	.register-view {
		height: 100%;
		padding: 0 48rpx;
		position: relative;
	}

	.logo {
		text-align: center;

		.register-image {
			margin-top: 149rpx;
			width: 170rpx;
			height: 170rpx;
		}
	}

	.input-all {
		margin-top: 99.6rpx;
		position: relative;
		
		.hint {
			color: #000000;
			font-family: PingFang SC;
			font-weight: 700;
			font-size: 32rpx;
			line-height: 40rpx;
			letter-spacing: 0rpx;
			text-align: left;
			position: absolute;
			top: -60rpx;
		}
		
		.ver-code {
			width: 194rpx;
			height: 56rpx;
			border-radius: 96rpx;
			background: #F1F1F1;
			text-align: center;
			line-height: 56rpx;
			color: #858585;
			font-size: 26rpx;
			position: absolute;
			top: 4rpx;
			right: 0;
		}

		.mobile-email {
			width: 100%;
			height: 56rpx;
			border-bottom: 2rpx solid #858585;
			padding: 8rpx 0;
		}

		.mobile-email::placeholder {
			color: #858585;
			font-family: PingFang SC;
			font-weight: regular;
			font-size: 30rpx;
			line-height: 40rpx;
			letter-spacing: 0rpx;
			text-align: left;
		}
		
		.password {
			width: 100%;
			height: 56rpx;
			border-bottom: 2rpx solid #858585;
			margin-top: 48rpx;
			padding: 8rpx 0;
		}
		
		.password::placeholder {
			color: #858585;
			font-family: PingFang SC;
			font-weight: regular;
			font-size: 30rpx;
			line-height: 40rpx;
			letter-spacing: 0rpx;
			text-align: left;
		}
		
		.vercode-err {
			color: #F44141;
			font-family: PingFang SC;
			font-weight: regular;
			font-size: 26rpx;
			letter-spacing: 0rpx;
			text-align: left;
			display: flex;
			align-items: center;
			margin-top: 12rpx;
		}
	}

	.ver-img {
		width: 26rpx;
		height: 26rpx;
		margin-right: 18rpx;
	}

	.register-but {
		height: 80rpx;
		width: 100%;
		border-radius: 20rpx;
		background: #000000;
		color: #FFFFFF;
		font-family: PingFang SC;
		font-weight: semibold;
		font-size: 28rpx;
		line-height: 80rpx;
		text-align: center;
		margin-top: 80rpx;
	}
</style>
